<template>
	<view class="page">
		<view class="row" @click="selectTypeShow=true">
			<view class="label">
				请假类型:
			</view>
			<view :class="selectLabel ? 'val' : 'empty'">
				{{selectLabel ? selectLabel : '请选择' }}
			</view>
		</view>
		<view class="row" @click="beginTimeShow=true">
			<view class="label" >
				开始时间:
			</view>
			<view :class="form.begTime ? 'val' : 'empty'">
				{{form.begTime ? form.begTime : '请选择' }}
			</view>
		</view>
		<view class="row" @click="endTimeShow=true">
			<view class="label">
				结束时间:
			</view>
			<view :class="form.endTime ? 'val' : 'empty'">
				{{form.endTime ? form.endTime : '请选择' }}
			</view>
		</view>
		<view class="row" style="height: 200rpx;">
			<view class="label">
				请假事由:
			</view>
			<view class="input">
				<u--textarea v-model="form.subjectContent" placeholder="请输入请假事由" ></u--textarea>
			</view>
		</view>
		<view class="btn" @click="handleConfirm">
			<text>确定</text>
		</view>
		
		<u-datetime-picker
		    :show="beginTimeShow" ref="datetimePicker" v-model="beginTime" 
		    mode="datetime"  @cancel="beginTimeShow=false" @confirm="beginTimeConfirm"
		       ></u-datetime-picker>
		<u-datetime-picker
			:show="endTimeShow" ref="datetimePicker" v-model="endTime" 
			mode="datetime"  @cancel="endTimeShow=false" @confirm="endTimeConfirm"
		   ></u-datetime-picker>
		
		<u-picker :show="selectTypeShow" :columns="selectList" keyName="label"
			@cancel="selectTypeShow = false"	@confirm="selectConfirm"></u-picker>
	</view>
</template>

<script>
	import {eltMemberAsksSave} from '@/common/api/commonApi/commonApi.js'
	export default {
		data() {
			return {
				form:{
					memberId : uni.getStorageSync('selectInfoAccount').id,
					category : '',
					subjectContent : '',
					remarks : '',
					begTime : '',
					endTime : '',
				},
				beginTime: Number(new Date()),
				endTime: Number(new Date()),
				beginTimeShow : false,
				endTimeShow : false,
				selectTypeShow : false,
				selectLabel : '',
				selectList : [
					[
						{
							label : '事假',
							val: 1
						},
						{
							label : '病假',
							val: 2
						},
					]
				]
			}
		},
		methods: {
			selectConfirm(e){
				this.selectLabel = e.value[0].label
				this.form.category = e.value[0].val
				this.selectTypeShow = false
			},
			beginTimeConfirm(e){
				let date = this.dateformat(e.value)
				this.form.begTime = date
				console.log(this.form.begTime);
				this.beginTimeShow = false
			},
			endTimeConfirm(e){
				let date = this.dateformat(e.value)
				this.form.endTime = date
				this.endTimeShow = false
			},
			handleConfirm(){
				if(!this.form.category) return this.setMessage('请假类型不能为空')
				if(!this.form.subjectContent) return this.setMessage('请假事由不能为空')
				if(!this.form.begTime) return this.setMessage('请选择开始时间')
				if(!this.form.endTime) return this.setMessage('请选择结束时间')
				eltMemberAsksSave(this.form).then(res=>{
					this.setMessage('操作成功')
					this.$emit('submitFin')
				})
			}
		},
		onLoad() {
		},
		onShow() {
			
		},
	}
</script>

<style lang="scss" scoped>
.page{
	background-color: #fff;
	height: 100vh;
	.text{
		color: #333;
	}
	.row{
		display: flex;
		align-items: center;
		height: 90rpx;
		padding: 0 30rpx;
		border-bottom: 2rpx solid #dcdcdc;
		&:nth-child(1){
			border-top: 2rpx solid #dcdcdc;
		}
		.label{
			width: 220rpx;
		}
		.val{
			padding-left: 20rpx;
		}
		.empty{
			padding-left: 20rpx;
			color: #c0c4cc;
		}
		.input{
			flex: 1;
			height: 100%;
			display: flex;
			align-items: center;
			.getCodeBtn{
				background-color: #4089f0;
				@include flexCenter;
				color: #fff;
				border-radius: 40rpx;
				height: 52rpx;
				width: 182rpx;
			}
		}
		
	}
	.btn{
		margin: 20rpx auto 0;
		background: #2d8cf6;
		@include flexCenter;
		width: 90vw;
		height: 92rpx;
		border-radius: 10rpx;
		text{
			color: #fff;
		}
	}
	
}
</style>
